TestBehaviorTree2 = BTBehaviorTree:New()

local this = TestBehaviorTree2
this.name = "TestBehaviorTree2"

function this:New()
	local o = {}
	setmetatable(o, self)
	self.__index = self
	o:Init()
	return o
end

function this:Init()
	local selector = BTSelector:New()
	local untilFailure = BTUntilFailure:New()
	local action = self:GetBTActionUniversal()
    local log = BTLog:New("This is a btree")

    self:SetStartTask(selector)
    untilFailure:AddChild(action)
    selector:AddChild(untilFailure)
    selector:AddChild(log)
end

function this:GetBTActionUniversal()
    local count = 1
    local a = function ()
        if (count == 1) then
            count = count + 1
            print("11")
            self.executionStatus = BTTaskStatus.Success
            return BTTaskStatus.Success
        elseif (count == 2) then
            count = count + 1
            print("22")
            self.executionStatus = BTTaskStatus.Running
            return BTTaskStatus.Running
        else
        	print("33")
            self.executionStatus = BTTaskStatus.Failure
            return BTTaskStatus.Failure
        end
    end
    local universal = BTActionUniversal:New(nil, a)
    return universal
end